import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/page/upload_elder_case_page.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/viewmodel/elder_case_list_view_model.dart';

class ElderCaseListPage extends BaseStatefulMvvmWidget {
  dynamic customerElderId;

  ElderCaseListPage({required this.customerElderId});

  @override
  State<StatefulWidget> createState() => _ElderCaseListState();
}

class _ElderCaseListState
    extends BaseMvvmRefreshState<ElderCaseListViewModel, ElderCaseListPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("电子档案"),
        actions: [
          TextButton(onPressed: () async {
            var data = await Go().push(UploadElderCasePage(elderId: widget.customerElderId));
            if(data!=null){
              viewModel.requestRefresh();
            }
          }, child: Text('上传电子档案'))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createScrollWidget() {
    var list =
        viewModel.listItems.map((e) => "${HttpApi.imageHead}${e.attachId}").toList();
    return GridView.count(
      crossAxisCount: 3,
      padding: EdgeInsets.symmetric(horizontal: 16,vertical: 12),
      children: list.map((e) => Hero(tag: e, child: ImageLoad(e,fit: BoxFit.cover,).toRound(borderRadius: 4.borderRadius)).onTap(() {
        showBigImage(context, list,position: list.indexOf(e));
      })).toList(),
      mainAxisSpacing: 10,
      crossAxisSpacing: 10,
    );
  }

  @override
  ElderCaseListViewModel createViewModel() {
    return ElderCaseListViewModel(context,
        customerElderId: widget.customerElderId);
  }

  @override
  bool get canPullUp => true;
}
